<%@page import="com.wanmait.shoppingsys.vo.UserInfo"%>
<%@page import="com.wanmait.shoppingsys.util.ShopCar"%>
<%@page import="com.wanmait.shoppingsys.util.Pager"%>
<%@page import="com.wanmait.shoppingsys.vo.Type"%>
<%@page import="com.wanmait.shoppingsys.vo.Specialty"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String path = request.getServletContext().getContextPath(); %>
<jsp:include page="/TypeController?action=type"></jsp:include>  
<jsp:include page="/inc/header.jsp"></jsp:include>
<div class="search_bar clearfix">
		<a href="index.jsp" class="logo fl"><img src="<%=path %>/images/logo.png"></a>
		<form class="search_con fl" action="<%=path %>/SpecialtyController?action=serach" method="post">
			<input type="text" class="input_text fl" name="serach_produit" placeholder="搜索商品">
			<input type="submit" class="input_btn fr" name="serach" value="搜索">
		</form>
		
		<div class="guest_cart fr">
			<a href="<%=path%>/order/index.jsp" class="cart_name fl">我的购物车</a>
			<%ShopCar shopCar = (ShopCar)session.getAttribute("shopCar");
			UserInfo userinfo = (UserInfo)session.getAttribute("userinfo");
			if(userinfo==null){%>
			<div class="goods_count fl" id="show_count">0</div>
			<%}else{if(shopCar==null){%>
			<div class="goods_count fl" id="show_count">0</div>
			<%}else{ %>
			<div class="goods_count fl" id="show_count"><%=shopCar.getTotalNumber() %></div>
			<%} %>
			<%} %>
		</div>
</div>

<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">i
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<% String cl[] = {"fruit","dryfruit","liquor","egg","tea","sea"}; %>
					<% ArrayList<Type> types = (ArrayList<Type>)request.getAttribute("types");
					for(int i=0;i<types.size();i++){
						Type type = types.get(i);
					%>
						<li><a href="<%=path %>/index.jsp#model0<%=type.getId() %>" class="<%=cl[i] %>"><%=type.getKind() %></a></li>
					<% 	
					}
					%>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="<%=path %>/index.jsp">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
				<li class="interval">|</li>
				<li><a href="<%=path %>/specialty/findbycity.jsp">按城市查找</a></li>
			</ul>
		</div>
	</div>
<%  Pager pager = (Pager)request.getAttribute("pager");
	ArrayList<Specialty> specialtys = (ArrayList<Specialty>)pager.getPageDate();
%>
	<div class="breadcrumb">
		<a href="<%=path%>">全部分类</a>
		<%if(specialtys.size()!=0){if(specialtys.get(0).getCity()==null){ %>
		<span>></span>
		<a href="#"><%=specialtys.get(0).getType().getKind() %></a>
		<%}else{ %>
		<span>></span>
		<a href="#"><%=specialtys.get(0).getCity().getName() %></a>
		<%}}else{%>
		<span></span>
		<% }%>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul> 
					<li>
						<a href="/ShoppingSys/SpecialtyController?action=detailed&id=112"><img src="<%=path %>/upload/博山猕猴桃.jpg"></a>
						<h4><a href="#">博山猕猴桃</a></h4>
						<div class="prize">￥50</div>
					</li>
					<li>
						<a href="/ShoppingSys/SpecialtyController?action=detailed&id=31"><img src="<%=path %>/upload/灵山岛海参.jpg"></a>
						<h4><a href="#">灵山岛海参</a></h4>
						<div class="prize">￥5.00</div>
					</li>	
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<div class="sort_bar">
				<%if(pager.getProduit()!=null){ %>
				<a href="<%=path%>/SpecialtyController?action=serach&serach_produit=<%=pager.getProduit() %>&order=1" class="<%=pager.getOrder()==1?"active":"" %>">默认</a>
				<a href="<%=path%>/SpecialtyController?action=produitbyprice&serach_produit=<%=pager.getProduit() %>&order=2" class="<%=pager.getOrder()==2?"active":"" %>">价格</a>
				<a href="<%=path%>/SpecialtyController?action=produitbylike&serach_produit=<%=pager.getProduit() %>&order=3" class="<%=pager.getOrder()==3?"active":"" %>">人气</a>
				<%}
				if(pager.getId()!=null){%>
				<a href="<%=path%>/SpecialtyController?action=findAll&id=<%=pager.getId() %>&order=1" class="<%=pager.getOrder()==1?"active":"" %>">默认</a>
				<a href="<%=path%>/SpecialtyController?action=typebyprice&id=<%=pager.getId() %>&order=2" class="<%=pager.getOrder()==2?"active":"" %>">价格</a>
				<a href="<%=path%>/SpecialtyController?action=typebylike&id=<%=pager.getId() %>&order=3" class="<%=pager.getOrder()==3?"active":"" %>">人气</a>
				<%} 
				if(pager.getCityId()!=null){%>
				<a href="<%=path%>/CityController?action=findbycity&cityId=<%=pager.getCityId() %>&order=1" class="<%=pager.getOrder()==1?"active":"" %>">默认</a>
				<a href="<%=path%>/CityController?action=citybyprice&cityId=<%=pager.getCityId() %>&order=2" class="<%=pager.getOrder()==2?"active":"" %>">价格</a>
				<a href="<%=path%>/CityController?action=citybylike&cityId=<%=pager.getCityId() %>&order=3" class="<%=pager.getOrder()==3?"active":"" %>">人气</a>
				<%} %>
			</div>

				<ul class="goods_type_list clearfix">
					<%
					for(int i=0;i<specialtys.size();i++){
						Specialty specialty = specialtys.get(i);
				
					%>
					<li>
						<a href="/ShoppingSys/SpecialtyController?action=detailed&id=<%=specialty.getId()%>"><img src="<%=path %>/upload/goods/<%=specialty.getPic()%>"></a>
						<h4><%=specialty.getName() %></h4>
						<div class="operate">
							<span class="prize">￥<%=specialty.getPrice() %></span>
							<%if(specialty.getType().getId()==3){%>
							<span class="unit"><%=specialty.getPrice() %>/瓶</span>
							<%}else{%>
							<span class="unit"><%=specialty.getPrice() %>/500g</span>
							<%}%>
							<a href="#" class="add_goods" title="加入购物车" onclick="shopcar(<%=specialty.getId()%>)"></a>
						</div>
					</li>
					<% 
					} 
					%>
			</ul>
		
			
			<%if(pager.getProduit()!=null){ %>
			<div class="pagenation">
				<%if(pager.hasPrev()){ %>
				<a href="<%=path%>/SpecialtyController?action=serach&pageNum=<%=pager.getPageNum()-1%>&serach_produit=<%=pager.getProduit() %>
				">上一页</a>
				<%} %>
				<%
				int k = 0;
				for(int i=pager.getPageNum();i<=pager.getPageCount();i++){
					k++;
				%>
				<a href="<%=path%>/SpecialtyController?action=serach&pageNum=<%=i%>&serach_produit=<%=pager.getProduit() %>"  class="<%=pager.getPageNum()==i?"active":"" %>"  ><%=i %></a>	
				<%if(k==5){break;} %>
				<%}%>
				<%if(pager.hasNext()) {%>
				<a href="<%=path%>/SpecialtyController?action=serach&pageNum=<%=pager.getPageNum()+1%>&serach_produit=<%=pager.getProduit() %>">下一页</a>
				<%} %>	
			</div>
			
			<%}
			if(pager.getId()!=null){ %>
			<div class="pagenation">
				<%if(pager.hasPrev()){ %>
				<a href="<%=path%>/SpecialtyController?action=findAll&pageNum=<%=pager.getPageNum()-1%>&id=<%=pager.getId() %> 
				">上一页</a>
				<%} %>
				<%
				int k = 0;
				for(int i=pager.getPageNum();i<=pager.getPageCount();i++){
					k++;
				%>
				<a href="<%=path%>/SpecialtyController?action=findAll&pageNum=<%=i%>&id=<%=pager.getId() %>"  class="<%=pager.getPageNum()==i?"active":"" %>"  ><%=i %></a>
				<%if(k==5){break;} %>
				<%}%>
				<%if(pager.hasNext()) {%>
				<a href="<%=path%>/SpecialtyController?action=findAll&pageNum=<%=pager.getPageNum()+1%>&id=<%=pager.getId() %>">下一页</a>
				<%} %>	
			</div>
			<%} 
			if(pager.getCityId()!=null){ %>
			<div class="pagenation">
				<%if(pager.hasPrev()){ %>
				<a href="<%=path%>/CityController?action=findbycity&pageNum=<%=pager.getPageNum()-1%>&cityId=<%=pager.getCityId() %> 
				">上一页</a>
				<%} %>
				<%
				int k = 0;
				for(int i=pager.getPageNum();i<=pager.getPageCount();i++){
					k++;
				%>
				<a href="<%=path%>/CityController?action=findbycity&pageNum=<%=i%>&cityId=<%=pager.getCityId() %>"  class="<%=pager.getPageNum()==i?"active":"" %>"  ><%=i %></a>
				<%if(k==5){break;} %>
				<%}%>
				<%if(pager.hasNext()) {%>
				<a href="<%=path%>/CityController?action=findbycity&pageNum=<%=pager.getPageNum()+1%>&cityId=<%=pager.getCityId() %>">下一页</a>
				<%} %>	
			</div>
			<%} %>	
		</div>
	</div>
<jsp:include page="/inc/footer.jsp"></jsp:include>
<script type="text/javascript">
function shopcar(id) {
	window.location.href="<%=path %>/ShopCarController?action=buy&id="+id+"&count=1";
}

$(".active1").click(function(){
	$(".active").css("background-color","#f0fdec");
	$(".active").css("color","#000");
	$(".active1").css("background-color","#37ab40");
	$(".active1").css("color","#fff");
	$(".active2").css("background-color","#f0fdec");
	$(".active2").css("color","#000");
})

</script>
    